<!-- App.vue -->
<template>
    <div id="app" class="font-inter bg-white text-gray-800 min-h-screen">
        <h2 style="text-align: center;color:#777;margin-top: 120px;">微信获取授权中...</h2>
    </div>
</template>

<script>

import { getConfigKey } from '@/api/system/config' // 导入配置API



export default {
    name: 'www',
    components: {
    },
    data() {
        return {
            appId: '',
        }
    },
    created() {
        this.init()
    },
    mounted() {

    },

    methods: {
        init() {
            let deptId = this.$route.query.deptId ? this.$route.query.deptId : ''
            let userId = this.$route.query.userId ? this.$route.query.userId : ''
            let tempToken = this.$route.query.tempToken ? this.$route.query.tempToken : ''
            let backPage = this.$route.query.backPage ? this.$route.query.backPage : ''
            getConfigKey('wx.appId').then(response => {
                this.appId = response.msg ? response.msg : ""

                if (!this.appId || this.appId == '') {
                    this.$message.error('未配置微信AppID，请在系统配置中设置wx.appId')
                    return
                }
                console.log("this.appId", this.appId)
                // 获取微信授权
                let url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +this.appId +'&redirect_uri=' + window.location.origin + backPage + '%3Fv%3D1'
                if (deptId) {
                    url += '%26deptId%3D' + deptId
                }
                if (userId) {
                    url += '%26userId%3D' + userId
                }
                if (tempToken) {
                    url += '%26tempToken%3D' + tempToken
                }
                url += '&response_type=code&scope=snsapi_userinfo&state=STATE'
                console.log(url)
                window.location = url
            });
        },

    }
}
</script>

<style scoped></style>